/*
** time.c for TIme in /home/vriely/Dropbox/work/Unix/Zappy_rendu/serv-src
**
** Made by Samuel Vrielynck
** Login   <vriely_s@epitech.net>
**
** Started on  Mon Jun 11 19:25:50 2012 Samuel Vrielynck
** Last update Thu Jul 19 18:11:57 2012 pierrick druart
*/

#include			"server.h"

static long unsigned int	getelappsedtime(struct timeval *beg,
    struct timeval *end)
{
  return (((end->tv_sec - beg->tv_sec) * MILLI) + end->tv_usec - beg->tv_usec);
}

long unsigned int		init_before_exe(t_game *game,
    struct timeval *beg)
{
  struct timeval		end;

  game->maxfd = game->serverfd;
  game->sleep = 0;
  if (gettimeofday(&end, NULL) != -1 && beg != NULL)
    return (getelappsedtime(beg, &end));
  perror("gettimeofday()");
  game->sleep = 1;
  return (0);
}

void				getsleeptime(long unsigned int *sleep,
    long unsigned int action)
{
  if (*sleep == 0)
    *sleep = action;
  else if (action != 0 && *sleep > action)
    *sleep = action;
}
